clc 
clear

T=1;
w=1/T;
t=linspace(0,pi,10000);
x=sawtooth(2*pi*t/T,0.5);
figure(1)
grid on


%傅里叶级数近似
k=1:2:41;
fourier_x=0;

for i =1:1:20
    fourier_x=fourier_x-8/(pi*pi*k(i)*k(i))*cos(2*pi*k(i)*t/T);
end
plot(t,fourier_x,'b')

%输入信号
R=1;
C=0.1;
w_0=1/(R*C);
hpf=(1i*k*2*pi*R*C/T)./(1+(1i*k*2*pi*R*C/T));

r_p = abs(hpf);
theta_p = angle(hpf);
fourier_x_hpf=0;

for i =1:1:20
    fourier_x_hpf = fourier_x_hpf- 8*r_p(i)/(k(i)^2 * pi^2)*cos(2*pi*k(i)*t/T+theta_p(i));
end

figure(2);
plot(t,x,'r');
grid on;
plot(t,fourier_x_hpf,'b')
